package com.soundnet.androidhelper.ui.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.soundnet.androidhelper.R;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class BaseActivity<T> extends AppCompatActivity implements Callback<T> {
    private int mLayoutId;
    private View mContentView;
    private ImageView mLeftImg;
    private TextView mLeftText;
    private ImageView mLeftMenuImg;
    private ImageView mTitleImg;
    private TextView mTitleText;
    private ImageView mRightImg;
    private RelativeLayout mLeftLayout;
    private RelativeLayout mRightLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void setLayoutId(int layoutId) {
        this.mLayoutId = layoutId;
        mContentView = LayoutInflater.from(this).inflate(mLayoutId,
                null);
        setContentView(mContentView);

        initTopView();
    }

    public void initTopView() {
        mLeftImg = (ImageView) mContentView.findViewById(R.id.left_img);
        mLeftLayout = (RelativeLayout) mContentView.findViewById(R.id.left_layout);
        mLeftText = (TextView) mContentView.findViewById(R.id.left_text);
        mLeftMenuImg = (ImageView) mContentView.findViewById(R.id.left_menu_img);
        mTitleImg = (ImageView) mContentView.findViewById(R.id.title_img);
        mTitleText = (TextView) mContentView.findViewById(R.id.title_text);
        mRightImg = (ImageView) mContentView.findViewById(R.id.right_img);
        mRightLayout = (RelativeLayout) mContentView.findViewById(R.id.right_layout);
    }

    public void setLeftImg(int resId) {
        if (mLeftImg != null) {
            mLeftLayout.setClickable(true);
            mLeftImg.setVisibility(View.VISIBLE);
            mLeftImg.setImageResource(resId);
        }
    }

    public void setLeftText(int textId) {
        if (mLeftText != null) {
            mLeftText.setVisibility(View.VISIBLE);
            mLeftText.setText(getString(textId));
        }
    }

    public void setLeftText(String text) {
        if (mLeftText != null) {
            mLeftText.setVisibility(View.VISIBLE);
            mLeftText.setText(text);
        }
    }

    public void setLeftMenuImg(int resId) {
        if (mLeftMenuImg != null) {
            mLeftMenuImg.setVisibility(View.VISIBLE);
            mLeftMenuImg.setImageResource(resId);
        }
    }

    public void setTitleImg(int resId) {
        if (mTitleImg != null) {
            mTitleImg.setVisibility(View.VISIBLE);
            mTitleImg.setImageResource(resId);
        }
    }

    public void setTitleText(int textId) {
        if (mTitleText != null) {
            mTitleText.setVisibility(View.VISIBLE);
            mTitleText.setText(getString(textId));
        }
    }

    public void setTitleText(String text) {
        if (mTitleText != null) {
            mTitleText.setVisibility(View.VISIBLE);
            mTitleText.setText(text);
        }
    }

    public void setRightImg(int resId) {
        if (mRightImg != null) {
            mRightLayout.setVisibility(View.VISIBLE);
            mRightImg.setVisibility(View.VISIBLE);
            mRightImg.setImageResource(resId);
        }
    }

    public View getmContentView() {
        return mContentView;
    }

    @Override
    public void onResponse(Call<T> call, Response<T> response) {
        Log.d("onResponse", "onResponse parent");
    }

    @Override
    public void onFailure(Call<T> call, Throwable t) {

    }
}
